package org.example.ychdp.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.ychdp.dao.ConcertDao;
import org.example.ychdp.entity.Concert;
import org.example.ychdp.entity.ConcertExample;
import org.example.ychdp.entity.User;
import org.example.ychdp.entity.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConcertService {
    @Autowired
    private ConcertDao concertDao;

    public PageInfo<Concert> searchConcert(Integer page, String nickname, String number) {
        PageHelper.startPage(page, 7);
        ConcertExample concertExample = new ConcertExample();
        ConcertExample.Criteria criteria = concertExample.createCriteria();
        criteria.andConcertnameLike("%" + nickname + "%");
        criteria.andArtistLike("%" + number + "%");
        List<Concert> userList = concertDao.selectByExample(concertExample);
        PageInfo<Concert> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }

    public List<Concert> selectAllConcert() {
        return concertDao.selectAllConcert();
    }

    public List<Concert> selectConcertToIndex(){
        return concertDao.selectConcertToIndex();
    }

    public Concert selectByPrimaryKey(Integer id){
        return concertDao.selectByPrimaryKey(id);
    }

    public int deleteConcertById(Integer concertId) {
        return concertDao.deleteByPrimaryKey(concertId);
    }

    public int insertConcert(Concert concert) {
        return concertDao.insertSelective(concert);
    }

    public Concert getConcertById(Integer id) {
        return concertDao.selectByPrimaryKey(id);
    }

    public int updateUser(Concert concert) {
        return concertDao.updateByPrimaryKey(concert);
    }
}
